package com.fyzk.activity.prize;

import com.alibaba.fastjson.JSON;
import com.fyzk.bean.JZPrizeInfo;
import com.fyzk.bean.JZPrizeResponse;
import com.fyzk.net.Commands;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import http.Common.CommandUtil;
import http.StringResultBean;

public class JZPrizeActivity extends JC_PrizeBaseActivity{
	private JZPrizeAdapter adapter;
	protected List<JZPrizeInfo> list_infor = new ArrayList<JZPrizeInfo>();
	
	@Override
	protected void init() {
		super.init();
		adapter = new JZPrizeAdapter(JZPrizeActivity.this, list_infor);
		listView.setAdapter(adapter);
	}

	@Override
	protected String getTopTitle() {
		return "竞彩足球开奖";
	}

	@Override
	public void jc_requestData() {
		super.jc_requestData();
		findJczqResults();
	}

	private void findJczqResults(){
		JSONObject obj = new JSONObject();
		try {
			obj.put("officialDate", currDate);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		httpPostJson(CommandUtil.FINDJCZQRESULTS, Commands.FINDJCZQRESULTS,obj,true);
	}

	@Override
	protected void onSuccess(int requestCode, StringResultBean resultBean, String result) {
		super.onSuccess(requestCode, resultBean, result);
		netProgressView.dismiss();
		JZPrizeResponse response = JSON.parseObject(resultBean.getData(),JZPrizeResponse.class);
		list_infor.clear();
		list_infor.addAll(response.getRaces());
		adapter.notifyDataSetChanged();
		int session = response.getRaces().size();
		time.setText(currDate + " " + weekTime + " 共" + session + "场");
	}

	@Override
	protected void onFailure(int requestCode, String errorCode,
							 String message) {
		if(errorCode.equals("20004")){
			time.setText(currDate + " " + weekTime + " 共0场");
			netProgressView.noneRecord(message);
		}else{
			netProgressView.fail(message);
		}
	}

}
